import multiprocessing
import os
import time


def loop():
    print("hello python process!")
    print("process id = {}, parent process id = {}".format(os.getpid(), os.getppid()))
    time.sleep(1)


cnt = 0


def consumer():
    global cnt
    while True:
        if cnt <= 0:
            time.sleep(1)
            continue
        cnt -= 1
        print("i am a consumer, cnt = {}, process id = {}".format(cnt, os.getpid()))


def producer():
    global cnt

    while True:
        cnt += 1
        print("i am a producer, cnt = {}, process id = {}".format(cnt, os.getpid()))
        time.sleep(1)


if __name__ == "__main__":
    # loop()
    p1 = multiprocessing.Process(target=consumer)
    p2 = multiprocessing.Process(target=producer)
    p1.start()
    p2.start()
